home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15634 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: mail2news.demon.co.uk!lorelei.demon.co.uk
  2. From: John Croudy <john@lorelei.demon.co.uk>
  3. Newsgroups: comp.lang.c++
  4. Subject: Operator Overloading
  5. Date: Sun, 7 Apr 96 19:05:44 GMT
  6. Organization: home
  7. Message-ID: <9604071905.AA001o6@lorelei.demon.co.uk>
  8. X-NNTP-Posting-Host: lorelei.demon.co.uk
  9. X-Newsreader: TIN [AMIGA 1.3 950726BETA PL0]
  10. X-Mail2News-Path: disperse.demon.co.uk!post.demon.co.uk!lorelei.demon.co.uk
  11.  
  12. Hello,
  13.  
  14. I have a question which I can't find the answer to in any of my books.
  15. It's very frustrating how books always seem to go into detail about what
  16. a pointer is (which I already know from C) but they always stop after
  17. introducing the advanced stuff.  I bought the books to learn C++ and
  18. they're 80% about C stuff, and the juicy stuff is skipped over...  like
  19. two pages on templates and a paragraph on references.  So I thought I'd
  20. ask here, because it's been driving me nuts.
  21.  
  22. Does anyone know about this form in C++:
  23.  
  24.        operator void*() const { return something; }
  25.  
  26. I found it in <streambuf.h> ... it seems to support the following
  27.  
  28.        ofstream file("TEST.DAT");
  29.  
  30.        if (file)      // File was opened ok
  31.  
  32. I then tried this:
  33.  
  34.        class MyClass
  35.        ...
  36.        operator double () const { return something; }
  37.        ...
  38.  
  39. and it seems to allow me to say
  40.  
  41.        double x;
  42.  
  43.        x = MyClass;
  44.  
  45. It seems to be a user-defined casting operator, but I can't find any
  46. mention of this in any books I have.  Can anyone explain what I have
  47. discovered here?
  48.  
  49. Thanks,
  50.  
  51. John
  52. xxxx
  53.